<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

//导入模型类 Order
use App\Model\Order;
// use App\Model\pro_goods;


use DB;


class OrderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {   
       // 获取搜索的参数 提取单个参数 
        $k = $request->input("keyword");

        // echo $k;
        // // 列表
        // // 分页
        // 
        // $data = Order::get();
        $data = Order::join('address','order.address_id','=','address.id')->where('name','like','%'.$k.'%')->paginate(2);
        // $data = Order::where('total','like','%'.$k.'%')->paginate(2);
        // dd($data);
        return view('Admin.Order.index',['data'=>$data,'request'=>$request->all()]);

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {   


        $data = DB::table('order')->where('id','=',$id)->value('status');
        if($data == 2) {
            DB::table('order') ->where('id','=', $id) ->update(['status' => 3]);
           return redirect('adminorder');
        } else {
            return back();
        }
    }

    //订单详情
    public function goods($id) {
       
        $data = DB::table('order_goods')->join('pro_goods','order_goods.goods_id','=','pro_goods.id')->where('order_id','=',$id)->first();
         

         // dd($data);
        return view('Admin.Order.goods',['data'=>$data]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        var_dump($_GET);
        dd($_GET);

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
